package  org.cocos2dx.javascript.Advert.gdt;

import android.app.Activity;
import android.util.Log;

import com.qq.e.ads.interstitial2.UnifiedInterstitialAD;
import com.qq.e.ads.interstitial2.UnifiedInterstitialADListener;
import com.qq.e.comm.util.AdError;
import org.cocos2dx.javascript.Advert.core.AdBase;

public class GDTInterstitialAd extends AdBase implements UnifiedInterstitialADListener {

    private UnifiedInterstitialAD mUnifiedInterstitialAD;

    @Override
    public void loadAd(Activity activity, boolean show) {
        mActivity = activity;
        mShow = show;
        if (mUnifiedInterstitialAD == null) {
            mUnifiedInterstitialAD = new UnifiedInterstitialAD(mActivity, GDTConstants.InterstitialPosID, this);
        }
        mUnifiedInterstitialAD.loadAD();
    }

    @Override
    public void showAd(Activity activity) {
        if (!mLoaded) {
            loadAd(activity, true);
            return;
        }
        mLoaded = false;
        mUnifiedInterstitialAD.show(mActivity);
    }

    @Override
    public void onADReceive() {

    }

    @Override
    public void onVideoCached() {

    }

    @Override
    public void onNoAD(AdError adError) {
        Log.d("gdt GDTInterstitialAd", adError.getErrorCode() + "onNoAD: " + adError.getErrorMsg());
    }

    @Override
    public void onADOpened() {

    }

    @Override
    public void onADExposure() {

    }

    @Override
    public void onADClicked() {

    }

    @Override
    public void onADLeftApplication() {

    }

    @Override
    public void onADClosed() {

    }

    @Override
    public void onRenderSuccess() {
        Log.d("gdt GDTInterstitialAd", "onRenderSuccess: ");
        mLoaded = true;
        if (mShow) {
            showAd(mActivity);
        }
    }

    @Override
    public void onRenderFail() {

    }
}
